Skip to main content

Time Machine

Reference - https://liaoxuefeng.com/books/git/tag/push-delete/index.html

1. Modify the file content

Original file content :

Git is a version control system.
Git is free software.

Update to :

Git is a distributed version control system.
Git is free software.

git status The command allows us to keep track of the current status of the repository. (Staged / Unstage status)

git status

git diff <file name> you can see the changes that has been modified.

git diff


Summary

  • To keep track of the status of your workspace at all times, use git status commands.
  • If git status it tells you that a file has been modified, git diff can view the modified content.

2. Version Rollback

Use git log command to view commit history

git log

Use git log --pretty=oneline when too dazzling

git log

The long string of similar numbers you see 1094adb...is commit id(version number)


  1. Make readme.md rollback to add distributed version
  • HEAD is the current version is represented by , which is the latest commit img
  • use git reset --hard HEAD^

--hard It will roll back to the last version's committed state

--soft will roll back to the last version's uncommitted state, and

--mixed it will roll back to the last version's added but uncommitted state.

Check readme.txt if the content is the version add distributed:

  • use cat <file name>

img

To restore the append GPL(cfcad45460d23c831be6178a6f5715916ce99de8) that have been reset:

  • As long as the command line window above has not been closed, you can search up and find the one append GPLt commit id
  • use git reset --hard <commit id>

img

When you forgot the commit id, you can use git reflog to find.

Summary

  • HEAD The version pointed to is the current version, so Git allows us to shuttle between version histories using commands git reset --hard <commit_id>
  • Before reverting, git log can view the commit history to determine which version to revert to.
  • To go back to the future, use git reflog to view the command history so that you can determine which version in the future you want to go back to.

3. Undo Modification

git checkout -- <file> This command discard all changes to the file in the workspace / unstage changes.

git reset HEAD <file> can use commands to undo (unstage) the changes in the temporary storage area and put them back into the working area.

img

4. Delete file

rm <file> This delete file command.